package edu.nf.project.webs.employeeAndCustomerInformation;

import edu.nf.project.entitys.entity.employeeAndCustomerInformation.convention.CustomerInfo;
import edu.nf.project.services.employeeAndCustomerInformation.CouponService;
import edu.nf.project.services.employeeAndCustomerInformation.CustomerInfoService;
import edu.nf.project.services.exception.derivedAnomalies.UsersException;
import edu.nf.project.services.response.BaseController;
import edu.nf.project.services.response.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 * @Author gjh
 * @Date 2025/6/3
 * @Description:
 */
@RestController
@RequestMapping("/api/customerInfo")
public class CustomerInfoController extends BaseController {
    @Autowired
    private CustomerInfoService customerInfoService;

    @GetMapping("/score")
    public ResultVO<CustomerInfo> getUserPoint(@RequestParam() String t_id) {
        try{
            CustomerInfo customerInfo =customerInfoService.findCustomerInfoPoint(t_id);
            return success(customerInfo);
        }catch (Exception e){
            System.out.println(e);
            throw new UsersException(10000, "系统错误，请稍后重试");
        }
    }

    @PostMapping("/updateScore")
    public ResultVO<Boolean> getUserNewPoint(@RequestParam() String t_id,@RequestParam() Integer point) {
        try{
            return success(customerInfoService.updateCouponCustomer(Integer.valueOf(t_id),point));
        }catch (Exception e){
            System.out.println(e);
            throw new UsersException(10000, "系统错误，请稍后重试");
        }
    }

    /**
     * 更新余额（复制了上面的方法，懒得改参数名）
     * @param t_id 用户ID
     * @param point 余额
     * @return 是否成功
     */
    @PostMapping("/updSurplus")
    public ResultVO<Boolean> updSurplus(@RequestParam() String t_id,@RequestParam() Integer point) {
        try{
            return success(customerInfoService.updSurplus(Integer.valueOf(t_id),point));
        }catch (Exception e){
            System.out.println(e);
            throw new UsersException(10000, "系统错误，请稍后重试");
        }
    }

    /**
     * 通过顾客ID获取用户ID
     * @param uId 顾客ID
     * @return 用户ID
     */
    @GetMapping("/useCusIdFindUId")
    public ResultVO<Integer> useCusIdFindUId(@RequestParam Integer uId) {
        try{
            return success(customerInfoService.useCusIdFindUId(uId));
        }catch (Exception e){
            System.out.println(e);
            throw new UsersException(10000, "系统错误，请稍后重试");
        }
    }
}
